using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Text.RegularExpressions;
using GeneratorLibrary.Client.Base;

namespace GeneratorLibrary.Client.iSeries {
    public class iSeriesOLEDataClass : ClassBase {


        protected override ClassColumnBase CreateColumn(DataRow row) {
            return new iSeriesOLEClassColumn(row);
        }

        protected override string GetExtraUsingStatements() {
            return "using System.Data.OleDb;\nusing StandardDAC.OleDb;\n";
        }

        public iSeriesOLEDataClass(DataTable dt, string table, string classNamespace, string dacNamespace, string dacName)
            : base(dt, table, classNamespace, dacNamespace, dacName) {
        }
        protected override string ReadById(string table) {
            return dacName + ".ReadById<" + table + ">(this, \"" + table + "\", allParametersOfReadProcInOrder);\n";
        }
        protected override string ReadAll(string table) {
            return "return " + dacName + ".ReadAll<" + table + ">(\"" + table + "\", allParametersOfReadProcInOrder);\n";
        }
        protected override string ReadByParams(string table, ClassColumnBase c, string parameterVariable) {
            return "return " + dacName + ".ReadByParams<" + table + ">(\"" + table + "\", " + dacName + ".newInParam(\"" + c.ColumnName + "\"), " + parameterVariable + ", allParametersOfReadProcInOrder);\n";
        }
        protected override string ExtraMembers() {
            string member = "static List<string> allParametersOfReadProcInOrder = new List<string>(new string[]{ ";

            string parameters = "";
            
            //assuming they are supported by column order, which they are...
            foreach (iSeriesOLEClassColumn c in this.columns) {
                if (c.IsPrimaryKey || c.IsForeignKey || c.IsUniqueConstraint || c.ColumnName.ToLower() == IsActiveColumn.ToLower()) {
                    parameters += ", \"" + c.ColumnName + "\"";
                }
            }
            if (parameters != "") {
                member += parameters.Remove(0, 2);
            }

            member += " });\n";


            return member;
        }
    }
}
